import 'package:flutter/material.dart';
import 'package:flutter_widget/src/config/color_define.dart';
import 'package:qr_flutter/qr_flutter.dart' as qrcode;

/*二维码*/
class QRCodeImage extends StatelessWidget {
  final String link; //链接
  final double? size; //大小，默认38
  final double? imageSize; //中间图片大小，默认13
  final EdgeInsets? padding; //间距
  final Color? backgroundColor; //背景色，默认无
  final Color? foregroundColor; //前景色，默认黑色
  final int? errorCorrectionLevel; //容错率，默认中等
  final ImageProvider? embeddedImage; //中间图标

  const QRCodeImage({
    Key? key,
    required this.link,
    this.size,
    this.imageSize,
    this.padding,
    this.backgroundColor,
    this.foregroundColor,
    this.errorCorrectionLevel,
    this.embeddedImage,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return qrcode.QrImage(
      backgroundColor: backgroundColor ?? FWColorPicker.clear,
      foregroundColor: foregroundColor ?? FWColorPicker.black,
      padding: padding ?? const EdgeInsets.all(0),
      data: link,
      size: size ?? 38,
      errorCorrectionLevel: errorCorrectionLevel ?? qrcode.QrErrorCorrectLevel.M,
      embeddedImage: embeddedImage,
      embeddedImageStyle: qrcode.QrEmbeddedImageStyle(
        size: Size(
          imageSize ?? 13,
          imageSize ?? 13,
        ),
      ),
    );
  }
}
